package com.parkwalk.xxx.util;

import java.io.FileReader;
import java.io.Reader;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * @author borball
 * @date 2012-4-29
 * 
 */
public class SessionFactory {

	private static SessionFactory instance;
	String resource = "config/db/xxx-config.xml";
	SqlSessionFactory sqlmapper;

	private SessionFactory() {
		init();
	}

	private void init() {
		try {
			Reader reader = new FileReader(resource);
			sqlmapper = new SqlSessionFactoryBuilder().build(reader);
		} catch (Exception e) {
			throw new RuntimeException("Initial Session Factory failed, " + e.getMessage());
		}
	}

	public static synchronized SessionFactory getInstance() {
		if (null == instance) {
			instance = new SessionFactory();
		}
		return instance;
	}

	public SqlSessionFactory getSqlSessionFactory() {
		return sqlmapper;
	}

}
